$('#global-header').addClass('dark');

if(window.location.hash){
  var destHash = window.location.hash;
  $(destHash).click();
}




var createSwipers = function(swiperArray){
setTimeout(function(){
  swiperArray.forEach(function(swiper){
    var swiper = new Swiper(swiper.node,{
      pagination: swiper.pagination,
      paginationClickable: true,
      autoplay: false,
      direction: 'horizontal',
      onClick: function(){
        if(swiper.activeIndex === (swiper.slides.length -1)){
          swiper.slideTo(0, 500, false)
        } else{
          swiper.slideNext()
        }
      },
      spaceBetween: 0,
      autoplayDisableOnInteraction: false
    })
  })
 }, 300)
}

var promoSwipers = [
  {
    pagination: '#commti-pagination',
    node: '#commti-swiper'
  },
  {
    pagination: '#pickle-pagination',
    node: '#pickle-swiper'
  },
  {
    pagination: '#xdqh-pagination',
    node: '#xdqh-swiper'
  },
  {
    pagination: '#dongxi-promo-pagination',
    node: '#dongxi-promo-swiper'
  },
  {
    pagination: '#heidian-pagination',
    node: '#heidian-swiper'
  }]

var devSwipers = [
  {
    pagination: '#timezen-pagination',
    node: '#timezen-swiper'
  },
  {
    pagination: '#gogo-pagination',
    node: '#gogo-swiper'
  }
]

var photoSwipers = [
  {
    pagination: '#xmoo-pagination',
    node: '#xmoo-swiper'
  },
  {
    pagination: '#dongxi-pagination',
    node: '#dongxi-swiper'
  },
  {
    pagination: '#emilio-pagination',
    node: '#emilio-swiper'
  }]

var designSwipers = [{
  pagination: '#xiemoyuan-pagination',
  node: '#xiemoyuan-swiper'
}]

createSwipers(promoSwipers)

$('#develop-tab').on('click', function(e){
  createSwipers(devSwipers)
})

$('#photo-tab').on('click', function(e){
  createSwipers(photoSwipers)
})
$('#design-tab').on('click', function(e){
  createSwipers(designSwipers)
})






var createVideos = function(selectorArray){
  selectorArray.forEach(function(selector){
    var video =$(selector + ' .video')[0];
    $(selector + ' .video')[0].addEventListener('ended', function() {
      video.pause();
      $(selector+' #play-pause').removeClass('playing');
    }, false);

    $(selector + ' #video-controls').off('click').click(function() {
      if (video.paused) {
        video.play();
        $(selector + ' #play-pause').addClass('playing');
      } else {
        video.pause();
        $(selector + ' #play-pause').removeClass('playing');
      }
    });
  })
}


var videosArray = ['#wuwa-video', '#wuwa-photog-video']
createVideos(videosArray)

